﻿using System;
using System.Web.UI;
using ASPNETVN.PORTAL.Components.UI.DataTypes;

namespace ASPNETVN.PORTAL.Components.Configuration.Settings
{
    public class ModuleSettingItem : IComparable
    {
        private string _Name = string.Empty;
        private readonly BaseDataType _DataType;
        private string _Description = string.Empty;
        private int _MaxValue;
        private int _MinValue;
        private int _Order;
        private bool _Required;
        private ModuleSettingItemGroup _ModuleSettingItemGroup = ModuleSettingItemGroup.Module_Special;

        public ModuleSettingItem(BaseDataType datatype)
        {
            this._DataType = datatype;
        }

        public ModuleSettingItem(BaseDataType datatype, string value)
        {
            this._DataType = datatype;
            this._DataType.Value = value;
        }


        public string Value
        {
            get { return this._DataType.Value; }
            set { this._DataType.Value = value; }
        }

        public string GroupDescription
        {
            get
            {
                switch (this._ModuleSettingItemGroup)
                {
                    case ModuleSettingItemGroup.None:
                        return "Generic settings";

                    case ModuleSettingItemGroup.Theme_Layout:
                        return "Theme and layout settings";

                    case ModuleSettingItemGroup.Security_User:
                        return "Users and Security settings";

                    case ModuleSettingItemGroup.Culture:
                        return "Culture settings";

                    case ModuleSettingItemGroup.Button_Display:
                        return "Buttons and Display settings";

                    case ModuleSettingItemGroup.Module_Special:
                        return "Specific Module settings";

                    case ModuleSettingItemGroup.Meta:
                        return "Meta settings";

                    case ModuleSettingItemGroup.Misc:
                        return "Miscellaneous settings";

                    case ModuleSettingItemGroup.Navigation:
                        return "Navigation settings";

                    case ModuleSettingItemGroup.Custom_User:
                        return "Custom User Settings";
                }
                return "Settings";
            }
        }

        public ModuleSettingItemGroup Group
        {
            get { return this._ModuleSettingItemGroup; }
            set { this._ModuleSettingItemGroup = value; }
        }

        public string Description
        {
            get { return this._Description; }
            set { this._Description = value; }
        }

        public bool Require
        {
            get { return this._Required; }
            set { this._Required = value; }
        }

        public BaseDataType DataType
        {
            get { return this._DataType; }
        }

        /// <summary>
        /// EditControl
        /// </summary>
        public Control EditControl
        {
            get
            {
                return this._DataType.EditControl;
            }
            set
            {
                this._DataType.EditControl = value;
            }
        }

        public int MaxValue
        {
            get { return this._MaxValue; }
            set { this._MaxValue = value; }
        }

        public int MinValue
        {
            get { return this._MinValue; }
            set { this._MinValue = value; }
        }

        public int Order
        {
            get { return this._Order; }
            set { this._Order = value; }
        }

        public string Name
        {
            get { return this._Name; }
            set { this._Name = value; }
        }

        #region IComparable Members

        public int CompareTo(object value)
        {
            if (value == null) return 1;
            int compareOrder = ((ModuleSettingItem)value).Order;
            if (this.Order == compareOrder) return 0;
            if (this.Order < compareOrder) return -1;
            if (this.Order > compareOrder) return 1;
            return 0;
        }

        #endregion

        public static implicit operator string(ModuleSettingItem value)
        {
            return (value.ToString());
        }

        public override string ToString()
        {
            if (this._DataType.Value != null)
            {
                return this._DataType.Value;
            }
            return string.Empty;
        }
    }
}